﻿package com.zkingsoft.services.pc.impl;

import com.zkingsoft.services.pc.PcMicroFoodService;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.pc.PcMicroFood;
import com.zkingsoft.dao.pc.PcMicroFoodDao;

import org.springframework.stereotype.Service;

import java.util.Map;

import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.util.ModelUtils;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-03-14 14:37
 */
@Service("pcMicroFoodService")
public class  PcMicroFoodServiceImpl implements    PcMicroFoodService  {

	
	@Autowired
	private PcMicroFoodDao pcMicroFoodDao;
	
	
	@Override
	public int add(PcMicroFood pcMicroFood){
		
		return pcMicroFoodDao.insert(pcMicroFood);
		
	}
	
	@Override
	public int batchAdd(List<PcMicroFood>  pcMicroFoodList) {
		int num = 0;

		int c = 10000;
		int size = pcMicroFoodList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= pcMicroFoodList.size() ? pcMicroFoodList.size() : end;
			List<PcMicroFood> insertList = pcMicroFoodList.subList(begin, end);
			num += pcMicroFoodDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(PcMicroFood oldPcMicroFood
	,PcMicroFood newPcMicroFood){
	
		if (!ModelUtils.isModified(oldPcMicroFood, newPcMicroFood)) {
			return 1;
		}
		Map<String, Object> modifyMap=null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldPcMicroFood, newPcMicroFood);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("mioId", oldPcMicroFood.getMioId());
			pcMicroFoodDao.updateByMap(modifyMap);
		}
		return 1;
	}
	
	@Override
	public int modifyByModel(PcMicroFood pcMicroFood){
	
		return pcMicroFoodDao.updateByModel(pcMicroFood);
	
	}
	
	
	
	@Override
	public int remove(List<Long> list){
	
		return pcMicroFoodDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(Long mioId){
	
		return pcMicroFoodDao.deleteById(mioId);
	
	}
	
	@Override
	public int removeByModel(PcMicroFood pcMicroFood){
	
		return pcMicroFoodDao.deleteByModel(pcMicroFood);
	
	}
	
	
	@Override
	public List<PcMicroFood> findInPage(PcMicroFood pcMicroFood,  PaginationVO pageVo){
	
		return pcMicroFoodDao.selectInPage(pcMicroFood , pageVo);
	
	}
	
	@Override
	public List<PcMicroFood> findByModel(PcMicroFood pcMicroFood){
	
		return pcMicroFoodDao.selectByModel(pcMicroFood);
	
	}
	
	@Override
	public int  findTotal(PcMicroFood pcMicroFood){
	
		return pcMicroFoodDao.selectTotalRecord(pcMicroFood);
	
	}
	
	@Override
	public PcMicroFood  findById(Long mioId){
	
		return pcMicroFoodDao.selectById(mioId);
	
	}
	/**
	 * 关联查询
	 */

	@Override
	public List<PcMicroFood> selectFoodMaterial(Long fodId) {
		
		return pcMicroFoodDao.selectFoodMaterial(fodId);
	}
	
   	
	
	
}